<?php
if (!defined('BASEPATH'))exit('No direct script access allowed');
//app接口通用函数
class App_common_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('Comment_model','comment');
        $this->load->model('Userhandle_model','userhandle_model');
        $this->load->model('Collect_model','collect_model');
    }
    //$typeFlag:0资讯 1:约见
	//是否点赞
	public function is_zan($userId,$listId,$flag=0){
	    if ($userId){
	        $flag=$this->userhandle_model->getUserZanRow($userId,$listId,$flag);     //0是点赞标记值 ,$typeFlag:0技师
	        if ($flag){
	            return true;
	        }else{
	            return false;
	        }
	    }else{
	        return false;
	    }
    }
    //是否点赞(对评论点赞)
    public function is_zan_comment($userId,$commentId,$flag=0){
        if ($userId){
            $flag=$this->userhandle_model->getUserZan($commentId,$userId,0,$flag);     //0是点赞标记值 ,
            if ($flag){
                return true;
            }else{
                return false;
            }
        }else{
            return false;
        }
    }
	//是否收藏
    public function is_collect($userId,$listId,$typeFlag=4){
        if ($userId){
            $flag=$this->collect_model->getWhereRow(['listId'=>$listId,'userId'=>$userId,'typeFlag'=>$typeFlag]);//4,店铺收藏,5项目收藏,6技师收藏 
            if ($flag){
                return true;
            }else{
                return false;
            }
        }else{
            return false;
        }
	}
	//详情页评论共用函数
	public function comment($listId,$userId=0,$typeFlag=0,$page=0){
	    
	    //获取评论总条数
	    $commentNum = $this->comment->getCountCommentNum($listId);
	    //获取评论信息
	    $searchParam = array('listId'=>$listId,'comment.deleteFlag'=>0,'comment.typeFlag'=>$typeFlag);
	    
	    $page=empty($page)?0:$page;
	    $limit = 20;
	    $offset=$page*$limit;
	    $select='commentId,comment.userId,zanNum,replyNum,content,comment.createTime,nickName,avatar';
	    $commentList = $this->comment->getDzCommentList($searchParam,$select, $limit,$offset);
	    foreach($commentList as $key=>$value)
	    {
	        //获取评论是否点赞
	        if ($userId){
	            $zan =$this->userhandle_model->getUserZan($value['commentId'],$userId);
	            if ($zan){
	                $is_zan=true;	                
	            }else{
	                $is_zan=false;
	            }
	        }else{
	            $is_zan=false;
	        }
	        $commentList[$key]['is_zan'] =$is_zan;	        
	        $commentList[$key]['createTime'] = format_time($value['createTime']);
	        
	    }
	    $comment=[
	        'commentNum'=>$commentNum,
	        'commentList'=>$commentList	        
	    ];
	    return $comment;
	}
	//获取评论详情页,即对一个评论的回复列表页
	public function getReply($commentId){	  
	    $select='commentId,comment.createTime,content,user.userId,nickName,avatar';
	    $replyList=$this->comment->getReplyList($commentId,$select);
	    if($replyList){
	        foreach ($replyList as $key=>$val){
	            $replyList[$key]['createTime']=format_time($val['createTime']);
	        }
	    }
	    return $replyList;	        
	}
	
	
	
	
	
	
	
	
	
	
	
}
?>